<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>待审核评论列表页</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/public.css">
<script type="text/javascript" src="${contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/common.js"></script>
<style type="text/css">
	.popover{
		max-width:none;
	}
</style>
</head>
<body>
	<jsp:include page="../head.jsp" />
	<div class="container">
		<div class="panel panel-default" id="waitInspCommentList">
			<div class="panel-heading">待审核评论列表</div>
			<div class="panel-body">
				<table style="table-layout: fixed;" class="table table-striped table-bordered">
					<thead>
						<tr>
							<th style="width: 5%">序号</th>
							<th style="width: 40%">内容</th>
							<th style="width: 20%">发布时间</th>
							<th style="width: 10%">发布人</th>
							<th style="width: 15%" colspan="2">操作</th>
						</tr>
					</thead>
					<tbody></tbody>
				</table>
			</div>
			<ul class="pagination"></ul>
		</div>
	</div>
<script type="text/javascript">
	var searchTitle = "";
	var searchUsername = "";
	$(document).ready(function () {
		waitInspCommentList(1);
	});
	waitInspCommentList = function (pageNum) {
		$.ajax({
			type: 'POST',
			url: '${contextPath}/security/waitInspCommentList',
			data: {"page": pageNum},
			dataType: 'json',
			success: function (data) {
				$("#waitInspCommentBadge").html(data.waitInspCommentCount);
				if (data.list == "") {
					$("tbody").empty();
					$("tbody").append("<tr class='text-danger'><td colspan='6'>无内容</td></tr>");
					var pageDom = $("#waitInspCommentList .pagination");
					pageDom.empty();
				} else {
					$("tbody").empty();
					$.each(data.list,function (i, item) {
						var commentContent = "";
						if(item.commentContent.length>30){
							commentContent = item.commentContent.substr(0,30)+"...";
						}else{
							commentContent = item.commentContent;
						}
						$("tbody").append(
							"<tr>"+
								 "<td>" + (i + 1) + "</td>" + 
								 "<td style=''><a tabindex='0' href='javascript:void(0);' role='button' data-container='body' title='评论内容' data-toggle='popover' data-trigger='focus' data-placement='right' data-content='"+ item.commentContent +"'>"+ commentContent +"</a></td>" + 
								 "<td>" + item.createTime + "</td>" + 
								 "<td>" + item.createUsername + "</td>" + 
								 "<td><a href='javascript:deleteComment(\""+item.id+"\")'>删除</a></td>" +
								 "<td><a href='javascript:commentIsGranted(\""+item.id+"\")'>审核通过</a></td>" +
							"</tr>"
						);
	
					});
					var pageDom = $("#waitInspCommentList .pagination");
					pageDom.empty();
					pucPageTotle = data.totlePage;
					page.creatPageHTML(pageNum, pucPageTotle, pageDom, "waitInspCommentList");
					$("#waitInspCommentList .pageGoBtn").click(function () {
						var pageNum = 0;
						pageNum = $("#waitInspCommentList .pageGoText").val();
						if (pageNum != 0 && 0 < pageNum && pageNum < pucPageTotle + 1) {
							loadUnCompletePackList(pageNum);
						}
					});
				}
				$('[data-toggle="popover"]').popover();
				$(".popover").css("max-width","none");
			}
		});
	};
	deleteComment = function (id) {
		var conWin = confirm("确定要删除该评论吗？");
		if (conWin) {
			$.ajax({
				type: 'POST',
				url: '${contextPath}/security/deleteComment',
				data: {"id": id},
				dataType: 'json',
				success: function (data) {
					if(data.replay==1){
						alert("评论删除成功!");
					}else{
						alert("评论删除失败,请联系系统维护人员!!");
					}
					waitInspCommentList(1);
				}
			});
		}
	};
	
	commentIsGranted = function (id) {
		var conWin = confirm("允许该评论发布吗？");
		if (conWin) {
			$.ajax({
				type: 'POST',
				url: '${contextPath}/security/commentIsGranted',
				data: {"id": id},
				dataType: 'json',
				success: function (data) {
					if(data.replay==1){
						alert("评论审核成功!");
					}else{
						alert("评论审核失败,请联系系统维护人员!!");
					}
					waitInspCommentList(1);
				}
			});
		}
	};
</script>
</body>
</html>
